package com.taomus.mytools.simplec.common;

public class SyntaxTuple {
	public final static int OPCODE = 0, T1 = 1, T2 = 2, T3 = 3;
	Token[] tuple = new Token[4];

	public SyntaxTuple() {
	}
	public SyntaxTuple(final Token opcode){
		this.tuple[OPCODE] = opcode;
	}
	public SyntaxTuple(final WordEnum opcode, final Token t1) {
		this.tuple[OPCODE] = new Token(opcode);
		this.tuple[T1] = t1;
	}
	public SyntaxTuple(final Token opcode, final Token t1) {
		this.tuple[OPCODE] = opcode;
		this.tuple[T1] = t1;
	}
	public void setAttribute(int offset,WordEnum attr){
		this.tuple[offset].setAttribute(attr);
		this.tuple[offset].setTo(attr);
	}
	public WordEnum getOpCode(){
		return this.tuple[OPCODE].getCode();
	}
	public WordEnum getCode(int index){
		if(this.tuple[index] != null){
			return this.tuple[index].getCode();
		}
		return WordEnum.EOF;
	}
	public String getSymbol(int index){
		return this.tuple[index].getSymbol();
	}
	/**
	 * 语法组构造函数
	 * 
	 * @param arg0
	 *            操作符
	 * @param arg1
	 *            符号
	 * @param arg2
	 *            类型 符号类型不确定时使用var
	 * @param arg3
	 *            常量或符号
	 */
	public SyntaxTuple(final Token arg0, final Token arg1, final Token arg2, final Token arg3) {
		this.tuple[OPCODE] = arg0;
		this.tuple[T1] = arg1;
		this.tuple[T2] = arg2;
		this.tuple[T3] = arg3;
	}

	public void setToken(int index, Token arg0) {
		this.tuple[index] = arg0;
	}

	public void opcode(Token arg0) {
		this.tuple[OPCODE] = arg0;
	}
	public WordEnum opcode(){
		return this.tuple[OPCODE].getCode();
	}
	public void t1(Token arg0) {
		this.tuple[T1] = arg0;
	}
	public Token t1(){
		return this.tuple[T1];
	}
	public void t2(Token arg0) {
		this.tuple[T2] = arg0;
	}
	public Token t2(){
		return this.tuple[T2];
	}

	public void t3(Token arg0) {
		this.tuple[T3] = arg0;
	}

	public Token t3(){
		return this.tuple[T3];
	}
	public Token getToken(int index) {
		if (4 > index) {
			return this.tuple[index];
		}
		return null;
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder("(");
		str.append(null != tuple[OPCODE] ? tuple[OPCODE].toString() : "");
		str.append(",");
		str.append(null != tuple[T1] ? tuple[T1].toString() : "");
		str.append(",");
		str.append(null != tuple[T2] ? tuple[T2].toString() : "");
		str.append(",");
		str.append(null != tuple[T3] ? tuple[T3].toString() : "");
		str.append(")");
		return str.toString();
	}

}
